<template>
  <div class="type">
    <Search :mess="mess" />
    <van-tree-select
      :items="type"
      height="93vh"
      :active-id.sync="activeId"
      :main-active-index.sync="activeIndex"
      @click-nav="leftfn"
    >
      <template #content>
        <div ref="right" class="right">
          <div v-for="item in contentsright" :key="item" class="right-item">
            <img :src="item.image" alt="" />
            <p>{{ item.text }}</p>
          </div>
        </div>
      </template>
    </van-tree-select>
  </div>
</template>

<script>
import instance from "../api/api";
import Search from "../components/Search.vue";
export default {
  name: "type",
  data() {
    return {
      mess: "高晓松",
      type: [],
      contentsright: [],
      activeId: 1,
      activeIndex: 0,
    };
  },
  components: {
    Search,
  },
  methods: {
    async getData() {
      let { data } = await instance("/api");
      console.log(data);
      this.type = data.type;
      this.contentsright = this.type[this.activeIndex].children;
    },
    leftfn(index) {
      // 点击左侧
      console.log(index);
      this.activeIndex = index;
      this.contentsright = this.type[index].children;
      // 获取右侧元素
      var xx = document.getElementsByClassName("van-tree-select__content");
      xx[0].scrollTop = 0;
      console.log(xx[0].scrollTop);
    },
  },
  created() {
    this.getData();
  },
};
</script>

<style lang="less" scoped>
.type {
  padding-bottom: 50px;
  box-sizing: border-box;
}
.van-sidebar::-webkit-scrollbar {
  display: none;
}
.van-tree-select__content::-webkit-scrollbar {
  display: none;
}
.right {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  .right-item {
    width: 80px;
    padding: 15px;
    box-sizing: border-box;
    margin-bottom: 16px;
    text-align: center;
    img {
      width: 56px;
      height: 56px;
    }
    p {
      font-size: 12px;
      color: #58595b;
    }
  }
}
</style>